﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Auto.Data.Report;
using System.Collections;
using BLL = Auto.Data.BusMan.BLL;
using Model = Auto.Data.BusMan.Model;



namespace Auto.BusMan.History
{
    public partial class SchBusRelatedInfoRecheckList : System.Web.UI.Page
    {
        ReportDocument ReportDoc;

        public string Type
        {
            get { return ViewState["DocID"].ToString(); }

            set { ViewState["DocID"] = value; }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.CrystalReportViewer1.DisplayGroupTree = false;

            if (!Page.IsPostBack)
            {
                InitPage();
            }
            else
            {
                if (this.Session["SchBusRelatedInfoRecheckList.ReportDoc"] != null)
                {
                    ReportDoc = (ReportDocument)Session["SchBusRelatedInfoRecheckList.ReportDoc"];
                    this.CrystalReportViewer1.ReportSource = ReportDoc;//绑定报表控件
                }
            }
        }
        private void InitPage()
        {
            this.ucDDLKeepDiv1.InitControl();
            string type = Request.QueryString["Type"];
            if (type == "AnnualChecking")
            {
                Type = "年审";
            }
            else if (type == "Insurance")
            {
                Type = "保险";
            }
            else if (type == "OperationCertification")
            {
                Type = "营运证";
            }

            Label2.Text = Type + "历史记录 "; 
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Display();
        }

        private void Display()
        {
            string dateMsg = "";


            //string strWhere = string.Empty;
            //if (this.ucDDLKeepDiv1.SelectedValue != "")
            //{
            //    strWhere += Model.BusList.FIELD_CompanyID + " ='" +ucDDLKeepDiv1.SelectedValue+"' ";
            //}
            //if (txtBusIdentificationNO.Text != "")
            //{
            //    strWhere += Model.BusList.FIELD_BusIdentificationNO + " LIKE '%" + txtBusIdentificationNO.Text + "%' ";
            //}
            //if (txtBusSpec.Text != "")
            //{
            //    strWhere += Model.BusList.FIELD_BusSpec + " LIKE '%" + txtBusSpec.Text + "%' ";
            //}

            DataTable dt = new BLL.BusRelatedInfoRecheckHistory().GetListWithDesc(ucDDLKeepDiv1.SelectedValue, txtBusIdentificationNO.Text, txtStartDate.CalendarDateText, txtEndDate.CalendarDateText,Type);

            dateMsg = "时间：" + txtStartDate.CalendarDateText + " 至 " + txtEndDate.CalendarDateText;

            ShowReport(dateMsg, dt);
        }

        //Method
        private void ShowReport(string Msg, DataTable dt)
        {

            if (ReportDoc == null)
            {
                ReportDoc = new ReportDocument();
            }
            ReportDoc.Load(Server.MapPath("rptCarRelatedInfoRecheckHistory.rpt"));//设置报表文档的路径 
            //设置成 A4纸，其它纸张见 MSDN
            ReportDoc.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4;
            ////设置报表方向为横向
            ReportDoc.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Portrait;

            ReportDoc.SetDataSource(dt);//绑定报表文档的数据源

            SortedList sl = new SortedList();
            ReportManager.FillRptToSortList(sl, "BusMan", ReportDoc, "rptCarInsList.rpt");
            sl.Add("txtTitle", "________公司");
            sl.Add("txtDateMsg",Msg);
            //sl.Add("DateMsg", Msg);
            //sl.Add("PrintDate", getDateFormatMode(DateTime.Now, true));
            this.CrystalReportViewer1.ReportSource = ReportDoc;//绑定报表控件
            CrystalReportViewer1.ParameterFieldInfo = ReportManager.SeedTextName(sl);// ReportCommand.SeedTextName(sl);
            this.Session["SchBusRelatedInfoRecheckList.ReportDoc"] = ReportDoc;
        }
    }
}